package com.detech.sbmh.base.domain;

import com.detech.sbmh.base.enumtype.CodeEnum;
import com.detech.sbmh.base.enumtype.MsgEnum;
import com.detech.sbmh.base.exception.LockException;
import com.detech.sbmh.base.exception.ServiceException;

//统一返回操作类
public class R {

    public static RE ajax(int num){
        if(num>0){
            return R.ok();
        }else{
            return R.fail();
        }
    }

	public static void serviceException(String message){
		throw new ServiceException(message);
	}

	public static void serviceException(String message, Object data){
		throw new ServiceException(message,data);
	}

	public static void serviceException(Integer code, String message, Object data){
		throw new ServiceException(code,message,data);
	}

	public static void lockException(String msg){
		throw new LockException(msg);
	}

	public static RE R(CodeEnum codeEnum, String msg) {
		return new RE(Message.custom(codeEnum.getCode(), msg), Message.num2HttpStatus(codeEnum.getCode()));
	}

	public static RE R(CodeEnum codeEnum, MsgEnum msg) {
		return new RE(Message.custom(codeEnum.getCode(), msg.getMsg()), Message.num2HttpStatus(codeEnum.getCode()));
	}

	public static RE R(CodeEnum codeEnum, String msg, Object data) {
		return new RE(Message.custom(codeEnum.getCode(), msg, data), Message.num2HttpStatus(codeEnum.getCode()));
	}

	public static RE R(CodeEnum codeEnum, MsgEnum msg, Object data) {
		return new RE(Message.custom(codeEnum.getCode(), msg.getMsg(), data), Message.num2HttpStatus(codeEnum.getCode()));
	}

	public static RE R(int code, String msg, Object data) {
		return new RE(Message.custom(code, msg, data), Message.num2HttpStatus(code));
	}

	public static RE ok() {
		return new RE(Message.custom(CodeEnum.success.getCode(), MsgEnum.OPRATE_SUCCESS.getMsg(), null), Message.num2HttpStatus(CodeEnum.success.getCode()));
	}

	public static RE ok(String msg) {
		return new RE(Message.custom(CodeEnum.success.getCode(), msg, null), Message.num2HttpStatus(CodeEnum.success.getCode()));
	}

	public static RE ok(Object data) {
		return new RE(Message.custom(CodeEnum.success.getCode(), MsgEnum.OPRATE_SUCCESS.getMsg(), data), Message.num2HttpStatus(CodeEnum.success.getCode()));
	}

	public static RE ok(String msg, Object data) {
		return new RE(Message.custom(CodeEnum.success.getCode(), msg, data), Message.num2HttpStatus(CodeEnum.success.getCode()));
	}

    public static RE fail() {
        return new RE(Message.custom(CodeEnum.fail.getCode(), CodeEnum.fail.getMsg(), null), Message.num2HttpStatus(CodeEnum.fail.getCode()));
    }

	public static RE fail(String msg) {
		return new RE(Message.custom(CodeEnum.fail.getCode(), msg, null), Message.num2HttpStatus(CodeEnum.fail.getCode()));
	}

	public static RE fail(String msg, Object data) {
		return new RE(Message.custom(CodeEnum.fail.getCode(), msg, data), Message.num2HttpStatus(CodeEnum.fail.getCode()));
	}

    public static RE checkFail() {
        return new RE(Message.custom(CodeEnum.logicCheck.getCode(), CodeEnum.logicCheck.getMsg(), null), Message.num2HttpStatus(CodeEnum.logicCheck.getCode()));
    }

    public static RE checkFail(String msg) {
        return new RE(Message.custom(CodeEnum.logicCheck.getCode(), msg, null), Message.num2HttpStatus(CodeEnum.logicCheck.getCode()));
    }

    public static RE checkFail(String msg, Object data) {
        return new RE(Message.custom(CodeEnum.logicCheck.getCode(), msg, data), Message.num2HttpStatus(CodeEnum.logicCheck.getCode()));
    }

    public static RE paramFail() {
        return new RE(Message.custom(CodeEnum.paramError.getCode(), CodeEnum.paramError.getMsg(), null), Message.num2HttpStatus(CodeEnum.paramError.getCode()));
    }

    public static RE paramFail(String msg) {
        return new RE(Message.custom(CodeEnum.paramError.getCode(), msg, null), Message.num2HttpStatus(CodeEnum.paramError.getCode()));
    }

    public static RE paramFail(String msg, Object data) {
        return new RE(Message.custom(CodeEnum.paramError.getCode(), msg, data), Message.num2HttpStatus(CodeEnum.paramError.getCode()));
    }

}
